// permission 模块是用来存放 静态路由和用户的路由权限
// 导入静态路由
import { asyncRoutes, constantRoutes } from '@/router'
const state = {
  routes: constantRoutes // 默认静态路由
}
const mutations = {
  setRoutes (state, newRoutes) {
    state.routes = [...constantRoutes, ...newRoutes]
  }
}
const actions = {
  // 通过下面函数筛选出用户信息中的动态路由给于主页侧边栏显示
  filterRoutes (context, menus) {
    console.log(menus)
    const routes = []
    //   筛选出 动态路由中和menus中能够对上的路由
    menus.forEach(key => {
      routes.push(...asyncRoutes.filter(item => item.name === key))
      context.commit('setRoutes', routes)
    })
    // 返回routes是为addRoutes用的
    return routes
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
